<template>
	<view class="main"><!--添加用户-->
		<view class="userInfo">
			<view>
				<view class="tit">信息填写</view>
				<view>为了更好的服务，请填写您的亲人信息</view>
			</view>
			<image src="@/static/images/addCont.png" style="width:260rpx;" mode='widthFix'></image>
		</view>
		<view class="userForm">
			<view class="userInput"><text>设备名称</text>
			<input placeholder="请为您绑定的设备设置一个名字" v-model="form.deviceNickName"></view>
			<view class="userInput"><text>设备编码</text>
			<input placeholder="请输入需要绑定设备的编码" v-model="form.deviceImei"></view>
			<view class="userInput"><text>设备位置</text>
			<input placeholder="设备安装位置，如客厅，卫生间" v-model="form.devicePosition"></view>
			
		</view>
		
	
	
		
		
		<view class="userbtn">
			<view class="btn btn1" @tap="backPage">取消</view>
			<view class="btn btn2" @tap="submit">确认添加</view>
		</view>
		
		
		
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form:{
				  "customerInfoId": "",
				  "deviceImei": "",
				  "deviceName": "",
				  "deviceNickName": "",
				  "devicePosition": "",
				  "deviceType": "",
				}
			}
		},
		onLoad(e){
			this.form.deviceType = e.typeId;
			this.form.customerInfoId = e.infoId;
			let list = this.$tools.deviceTypeList();
			for(let i in list){
				if(e.typeId == list[i].id){
					this.form.deviceName = list[i].name1;
					break;
				}
			}
		},
		methods: {
			backPage(){
				this.$tools.backPrePage(`/pages/userInfo/userInfo?id=${this.customerInfoId}`)
			},
			submit(){
				if(!this.form.deviceNickName){
					this.$tools.msg("请输入设备名称")
					return;
				}
				if(!this.form.deviceImei){
					this.$tools.msg("请输入设备编码")
					return;
				}
				if(!this.form.devicePosition){
					this.$tools.msg("请输入设备位置")
					return;
				}
				
				this.$http.addlnfoDevice(this.form).then(res=>{
					if(res.code==0){
						this.$tools.msg("添加设备成功！")
						setTimeout(res=>{
							uni.navigateTo({
								url: `/pages/userInfo/userInfo?id=${this.form.customerInfoId}`,
								success: res => {},
								fail: () => {},
								complete: () => {}
							});
						},2000)
					}else{
						this.$tools.msg(res.msg);
					}
				})
				
				
				
				
			}
		}
	}
</script>

<style scoped lang="scss">
	@import url("@/css/app.scss");
	
	
</style>
